package enumdemo;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {

    //枚举与反射的结合
    public static void main(String[] args) {

        Class<?> c1 = null;
        try {
            c1 = Class.forName("enumdemo.TestEnum");

            //枚举这个地方十分特殊，我们需要获取到这个方法，必须传四个参数
            //另外两个参数，我们需要给到它的父类
            Constructor<TestEnum> constructor =
                    (Constructor<TestEnum>)c1.getDeclaredConstructor
                            (String.class,int.class,int.class,String.class);
            constructor.setAccessible(true);

            TestEnum testEnum = constructor.newInstance(18,"白色");

            System.out.println(testEnum);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
